<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Role Access
 *
 * @author Samuel Pulta
 */
class Role_Access extends Brochure {
    //put your code here
    
    //public $unique_id;
    public $id;
    public $page_access;	
    public $level_id;	
    public $access_type;
    public $created_by;
    public $modified_by;
    public $date_created;	
    public $date_modified;	
    public $is_active;	


    
    public function __construct($db, $id) {
        $this->init($db, $id);
    }
    
    public function init($db, $id){
        $this->db = $db;
        $this->tblname = TB_ROLE_ACCESS;
        $this->id = $id;
        
            if($id){
                $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "row");
    
                $this->id   =   $result['id'];
                $this->page_access   =   $result['page_access'];	
                $this->level_id   =   $result['level_id'];	
                $this->access_type   =   $result['access_type'];
                $this->created_by   =   $result['created_by'];
                $this->modified_by   =   $result['modified_by'];	
                $this->date_created   =   $result['date_created'];	
                $this->date_modified   =   $result['date_modified'];	
                $this->is_active   =   $result['is_active'];	


            }
       
    }
    
    public function query_array(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "array");
        return  $result;
    }
    
    public function query_numrows(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname), "numrows");
        return $result;
    }
    
    public function save() {
        $insert_array = array(
            "page_access"               =>  $this->page_access,	
            "level_id"                   =>  $this->level_id,	
            "access_type"               =>  $this->access_type,
            "created_by"               =>  $this->created_by,
            "modified_by"               =>  $this->modified_by,
            "date_created"              =>  $this->date_created,	
            "date_modified"             =>  $this->date_created,	
            "is_active"                 =>  $this->is_active

        );
    
        $insert_id = $this->db->insert($this->db->tbl_name($this->tblname), $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            "page_access"               =>  $this->page_access,	
            "level_id"                   =>  $this->level_id,	
            "access_type"               =>  $this->access_type,
            "created_by"               =>  $this->created_by,
            "modified_by"               =>  $this->modified_by,
            "date_created"              =>  $this->date_created,	
            "date_modified"             =>  $this->date_created,	
            "is_active"                 =>  $this->is_active
        );
    
        $condition_array = array("id" => $this->id);
    
        $this->db->update($this->db->tbl_name($this->tblname), $update_array, $condition_array);
    }
}

?>
